// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Interface/IRuleCharacter.h"
#include "Core/GameCore/TowerDefenceGameState.h"
#include "Core/GameCore/TowerDefencePlayerController.h"
#include "RuleCharacter.generated.h"



UCLASS()
class TF_20240717_API ARuleCharacter : public ACharacter, public IRuleCharacter
{
	GENERATED_BODY()

	// 跟踪点
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttribute", meta=(AllowPrivateAccess=true))
	USceneComponent* HomingPoint;
	
	// 显示角色信息的UI
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttribute", meta=(AllowPrivateAccess=true))
	class UWidgetComponent* Widget;

	// 开火点
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttribute", meta=(AllowPrivateAccess=true))
	UArrowComponent* OpenFirePoint;
	
	// 射线捕捉对象
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="BaseAttrubute", meta=(AllowPrivateAccess=true))
	class UBoxComponent* TraceShowCharacterInformation;
	


protected:
	virtual void BeginPlay() override;
	
	virtual float TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;

	virtual bool IsDeath() override;
	virtual float GetHealth() override;
	virtual float GetMaxHealth() override;
	virtual bool IsTeam() override;
	virtual EGameCharacterType::Type GetType() override;
	
public:
	ARuleCharacter();
	virtual void Tick(float DeltaTime) override;

	// 获取玩家控制器（第一个玩家的）
	FORCEINLINE  ATowerDefencePlayerController* GetGameController() const { return GetWorld() ? Cast<ATowerDefencePlayerController>(GetWorld()->GetFirstPlayerController()) : nullptr; }

	// 获取玩家状态（通过模板的方式获取 GameState，也可以用上边获取控制的方法， Cast<> 转换）
	FORCEINLINE ATowerDefenceGameState* GetGameState() const {return GetWorld() ? GetWorld()->GetGameState<ATowerDefenceGameState>() : nullptr; }

	// 获取追踪点
	FORCEINLINE USceneComponent* GetHomingPoint() const {return HomingPoint; }
	// 获取开火点
	FORCEINLINE UArrowComponent* GetFirePoint() const {return OpenFirePoint; }
};
